package cn.com.hp.feature.onfig;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户信息初始化配置
 * @author hongjuzhu
 * @date 2022/3/29
 */
@Slf4j
@Data
public class UserProperties {
    private static final  ThreadLocal<Map<String,String>> currentUser = new ThreadLocal<>();
    private static String USER_ID ="userId";
    private static String TENANT_ID ="tenantId";

    /**
     * 是否开启BU查询
     */
    private Boolean enable = false;

    public static void setCurrentUserId(String userId,String tenantId) {
        Map<String,String> headerData = new HashMap<>();
        log.info("用户Id:userId set to " + userId);
        log.info("tenantId:tenantId set to " + tenantId);
        headerData.put(USER_ID,userId);
        headerData.put(TENANT_ID,tenantId);
        currentUser.set(headerData);
    }

    public static String getCurrentUserId(String key) {
        Map<String,String> headerData = currentUser.get();
        return headerData==null?"":headerData.get(key);
    }

    public static String getCurrentUserId() {
        Map<String,String> headerData = currentUser.get();
        return headerData==null?"":headerData.get(USER_ID);
    }

    /**
     * 不需要过滤BU的表
     */
    //private List<String> ignoreTables = Arrays.asList("subscribe_access_log");
    private List<String> ignoreTables = Arrays.asList();

    /**
     * BU字段名称
     */
    private String column = "tenant_id";

    public boolean getEnable() {
        return true;
    }

}
